package com.liang.jiekou.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liang.jiekou.entity.Result;
import com.liang.jiekou.entity.RpcServiceResult;
import com.liang.jiekou.entity.dto.JhdByPurDto;
import com.liang.jiekou.entity.dto.JhdDto;
import com.liang.jiekou.entity.dto.backDto;
import com.liang.jiekou.entity.result.COPTCD;
import com.liang.jiekou.entity.result.PURTCD;
import com.liang.jiekou.service.PURTCDService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Map;

@Api(tags = "采购控制器")
@RestController
@RequestMapping("/cg")
public class PURTCDController {

    @Resource
    private PURTCDService purtcdService;


    @ApiOperation("根据单别单号查询采购单信息")
    //查询采购单信息
    @GetMapping("/selectPURTCD")
    public PURTCD selectPURTCD(@RequestParam String TC001,@RequestParam String TC002){
       return  purtcdService.selectPURTCD(TC001, TC002);
    }



    @ApiOperation("查询全部采购单的信息")
    @GetMapping("/selectPURTCD/all")
    public Result<Page<PURTCD>> selectINVMBall(@RequestParam Integer page, @RequestParam Integer pageSize,
                                                String startcreate, String endcreate, String startupdate, String endupdate
    ){
        Page<PURTCD> purtcdPage = purtcdService.selectPurtcdcdPage(page, pageSize,startcreate,endcreate,startupdate,endupdate);

        return Result.success(purtcdPage);

    }

    @ApiOperation("根据到货单产生进货单并自动审核")
    @PostMapping("/insertjhdByArr")
    public RpcServiceResult<Map<String, Object>> insertjhd(@RequestBody JhdDto jhdDto) throws UnknownHostException {
        return purtcdService.insertjhd(jhdDto);
    }

    @ApiOperation("根据采购单产生进货单")
    @PostMapping("/insertjhdByPur")
    public RpcServiceResult<Map<String, Object>> insertjhdByPur(@RequestBody JhdByPurDto jhdDto) throws UnknownHostException{
        return purtcdService.insertjhdByPur(jhdDto);
    }

    @ApiOperation("撤销进货单")
    @PostMapping("/backJhd")
    public RpcServiceResult backJhd(@RequestBody backDto backDto) throws UnknownHostException {
        return purtcdService.backJhd(backDto);
    }
}
